package com.lanou.controller;

import com.github.pagehelper.PageInfo;
import com.lanou.bean.Account;
import com.lanou.bean.Cost;
import com.lanou.bean.Service;
import com.lanou.service.CostService;
import com.lanou.service.ServiceService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by dllo on 18/3/13.
 */
@Controller
public class CostController {
    @Resource
    private CostService costService;
    @Resource
    private ServiceService serviceService;

    @RequestMapping(value = "/feelist")
    public String cost() {
        return "fee/fee_list";
    }

    @ResponseBody
    @RequestMapping(value = "/listfee")
    public PageInfo<Cost> feePage(@RequestParam("pagenum") Integer pageNo) {
        return costService.queryCostByPage(pageNo, 4);
    }

    @ResponseBody
    @RequestMapping(value = "/serviceAccountCost")
    public List<Service> serviceAccountCost() {
        return serviceService.allservice();
    }

    @ResponseBody
    @RequestMapping(value = "/selectCostById")
    public List<Service> selectCostById(@RequestParam("costId") Integer costId) {
        return serviceService.selectCostById(costId);
    }

    @RequestMapping(value = "/billList")
    public String billList() {
        return "bill/bill_list";
    }

    @RequestMapping(value = "/billItem")
    public String billItem() {
        return "bill/bill_item";
    }

    @RequestMapping(value = "/billServiceDetail")
    public String billServiceDetail() {
        return "bill/bill_service_detail";
    }

    @ResponseBody
    @RequestMapping(value = "/costPage")
    public PageInfo<Service> queryCostByPage(@RequestParam("pagenum") Integer pageNo) {
        return serviceService.queryCostByPage(pageNo, 3);
    }

    @RequestMapping(value = "/feeAdd")
    public String costAdd() {
        return "fee/fee_add";
    }

    @ResponseBody
    @RequestMapping(value = "/addcost")
    public void addcost(@RequestParam("name") String name, @RequestParam("baseDuration") Integer baseDuration, @RequestParam("baseCost") Integer baseCost, @RequestParam("unitCost") Integer unitCost, @RequestParam("descr") String descr, @RequestParam("costType") String costType) {
        costService.addAll(name, baseDuration, baseCost, unitCost, descr, costType);
    }

    @RequestMapping(value = "/costupdate")
    public String costupdate() {
        return "fee/fee_modi";
    }

    @ResponseBody
    @RequestMapping(value = "/selectcostbyid")
    public Cost selectcostbyid(@RequestParam("costid") Integer costid) {
        System.out.println(costService.selectcostbyid(costid));
        return costService.selectcostbyid(costid);
    }

    @ResponseBody
    @RequestMapping(value = "/updatecost")
    public void updatecost(@RequestParam("name") String name, @RequestParam("baseDuration") Integer baseDuration, @RequestParam("baseCost") Integer baseCost, @RequestParam("unitCost") Integer unitCost, @RequestParam("descr") String descr, @RequestParam("costid") Integer costid) {
        costService.updatecost(name, baseDuration, baseCost, descr, costid);
    }

    @ResponseBody
    @RequestMapping(value = "/deletecost")
    public void deletecost(@RequestParam("costid") Integer costid) {
        costService.deletecost(costid);
    }

    @RequestMapping(value = "/detail")
    public String feedetail(){
        return "fee/fee_detail";
    }
    @RequestMapping(value = "/reportList")
    public String reportList() {
        return "report/report_list";
    }

    @ResponseBody
    @RequestMapping(value = "/updateStatusByCostId")
    public void updateStatusByCostId(@RequestParam("status") String status, @RequestParam("costId") Integer costId) {
        costService.updateStatusByCostId(status, costId);
    }

    @ResponseBody
    @RequestMapping(value = "/costbaseAsc")
    public PageInfo<Cost> costbaseAsc(@RequestParam("pagenum") Integer pageNo) {
        return costService.costbaseasc(pageNo, 4);
    }

    @ResponseBody
    @RequestMapping(value = "/costbaseDesc")
    public PageInfo<Cost> costbaseDesc(@RequestParam("pagenum") Integer pageNo) {
        return costService.costbasedesc(pageNo, 4);
    }

    @ResponseBody
    @RequestMapping(value = "/costtiemAsc")
    public PageInfo<Cost> costtiemAsc(@RequestParam("pagenum") Integer pageNo) {
        return costService.costtiemasc(pageNo, 4);
    }

    @ResponseBody
    @RequestMapping(value = "/costtiemDesc")
    public PageInfo<Cost> costtiemDesc(@RequestParam("pagenum") Integer pageNo) {
        return costService.costtiemdesc(pageNo, 4);
    }
}
